/**
 * 
 */
package com.cqan.entity.account;

import java.util.List;

import javax.persistence.*;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.cqan.entity.pk.IdEntity;

/**
 * @author wuhui
 *
 * 下午03:03:38
 */
@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "SYS_ROLE")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends IdEntity {

	private String roleName;
	
	private String roleEname;
	
	/**
	 * 状态 0:正常，1:停用
	 */
	private Byte status;
	
	private List<User> users;

	private List<Organization> orgs;
	
	
	private List<Permission> permissions;
	

	//多对多定义
	@ManyToMany
	//中间表定义,表名采用默认命名规则
	@JoinTable(name = "SYS_ROLE_PERMISSION", joinColumns = { @JoinColumn(name = "rid") }, inverseJoinColumns = { @JoinColumn(name = "pid") })
	//Fecth策略定义
	@Fetch(FetchMode.SUBSELECT)
	//集合按id排序.
	@OrderBy("id")
	//集合中对象id的缓存.
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Permission> getPermissions() {
		return permissions;
	}

	@ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "roles",fetch = FetchType.LAZY)
	public List<Organization> getOrgs() {
		return orgs;
	}

	public String getRoleEname() {
		return roleEname;
	}

	public String getRoleName() {
		return roleName;
	}

	public Byte getStatus() {
		return status;
	}

	@ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "roles",fetch = FetchType.LAZY)
	public List<User> getUsers() {
		return users;
	}


	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}

	public void setOrgs(List<Organization> orgs) {
		this.orgs = orgs;
	}

	
	public void setRoleEname(String roleEname) {
		this.roleEname = roleEname;
	}

	
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	
	public void setStatus(Byte status) {
		this.status = status;
	}

	
	public void setUsers(List<User> users) {
		this.users = users;
	}
	
	
}
